package servlets;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import utility.UserSession;

public class AddUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
            response.setContentType("text/html");
                                    
            /**
             * Getting parameters from Register.jsp
             */

            String emailID = request.getParameter("emailID");
            String password = request.getParameter("password");
            String question = request.getParameter("question");
            String answer = request.getParameter("answer");
            //System.out.println("Inside Servlet");
            UserSession sess = new UserSession();
             String message=sess.addUser(emailID,password,question,answer);
             if(message.equals("Success"))
             {
            	 request.setAttribute("message", "Welcome to Quiz System SiQuoia!!");
                 RequestDispatcher RequestDispatcherObj =request.getRequestDispatcher("/view/UserHome.jsp");
                 RequestDispatcherObj.forward(request, response);
             }
             else
             {
            	 request.setAttribute("message", message);
                 RequestDispatcher RequestDispatcherObj =request.getRequestDispatcher("/view/Register.jsp");
                 RequestDispatcherObj.forward(request, response);
             }
     }
          
}
